﻿using System;
using Newtonsoft.Json;

namespace SlickGridNet.Serialization
{
	public class ExplicitStringConverter : JsonConverter
	{
		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			IExplicitString expString = value as IExplicitString;
			if (expString == null || expString.Value == null)
				writer.WriteNull();
			else
				writer.WriteRawValue(expString.Value);
		}

		public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			// NOTE: reading from JSON not supported now
			throw new NotImplementedException();
		}

		public override bool CanConvert(Type objectType)
		{
			// NOTE: not used as converter class associated with object over attribute
			throw new NotImplementedException();
		}
	}
}